package com.rzwl.single.server.entity;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;

/**
 * @author : championjing
 * @ClassName: Score
 * @Description: TODO
 * @Date: 2020-08-02 19:35
 */
@EntityListeners(AuditingEntityListener.class)
@Entity
@Table(name = "score")
@Data
public class Score implements Serializable {
    private static final long serialVersionUID = -8366929034564774130L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String openid;
    private Integer over;
    private String lef;
    private String righ;
    @CreatedDate
    @Basic
    private Timestamp ctime;
    
    public ScoreVO transfer(){
        ScoreVO scoreVO = new ScoreVO();
        
        scoreVO.setId( this.getId() );
        scoreVO.setOpenid( this.getOpenid() );
        scoreVO.setOver( this.getOver() );
        scoreVO.setLef(JSON.parseObject( this.getLef(), TeamScore.class ));
        scoreVO.setRigh(JSON.parseObject( this.getRigh(), TeamScore.class ));
        scoreVO.setCtime( this.getCtime() );
        
        return scoreVO;
    }
}
